package com.xiao.train.member.controller;

import com.xiao.train.common.context.LoginMemberContext;
import com.xiao.train.common.resp.CommonResp;
import com.xiao.train.member.req.PassengerQueryReq;
import com.xiao.train.member.req.PassengerSaveReq;
import com.xiao.train.member.service.PassengerService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("passenger")
public class PassengerController {

    @Autowired
    PassengerService passengerService;

    @PostMapping("save")
    public CommonResp save(@Valid @RequestBody PassengerSaveReq req) {
        passengerService.save(req);
        return new CommonResp();
    }

    @GetMapping("query-list")
    public CommonResp queryList(@Valid PassengerQueryReq req) {
        req.setMemberId(LoginMemberContext.getId());
        return new CommonResp(passengerService.queryList(req));
    }

    @DeleteMapping("delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        passengerService.delete(id);
        return new CommonResp();
    }

    @GetMapping("query-mine")
    public CommonResp queryMine() {
        return new CommonResp(passengerService.queryMine());
    }
}